package com.baizhi.controller;


import com.baizhi.entity.Auction;
import com.baizhi.entity.Record;
import com.baizhi.entity.User;
import com.baizhi.service.AuctionService;
import com.baizhi.service.RecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/rc")
public class RecordController {
    @Autowired
    private RecordService rs;
    @Autowired
    private AuctionService as;

    public AuctionService getAs() {
        return as;
    }

    public void setAs(AuctionService as) {
        this.as = as;
    }

    public RecordService getRs() {
        return rs;
    }

    public void setRs(RecordService rs) {
        this.rs = rs;
    }

    @RequestMapping("/selectRecordAndUser")
    public String selectRecordAndUser(int id, Map map){
        List<Record> recordList=rs.selectRecordAndUser(id);
        map.put("recordList",recordList);
        System.out.println(recordList);
        Auction auction=as.selectOne(id);
        System.out.println();
        map.put("auction",auction);
        return "page/jingpaiye";
    }
    @RequestMapping("/add")
        public String add(Record record, HttpSession session){
        User user=(User) session.getAttribute("user");
        System.out.println(record);
        System.out.println(user);
        int user_id=user.getUser_id();
        record.setUser_id(user_id);
        rs.add(record);
        return "redirect:/selectAllAuction";
        }
}
